package com.hangzhou.xyj.ui.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.hangzhou.xyj.R;
import com.hangzhou.xyj.manager.IntentManager;
import com.hangzhou.xyj.model.DianDramaModel;
import com.hangzhou.xyj.model.SingModel;
import com.hangzhou.xyj.model.type.EIntentTagType;
import com.hangzhou.xyj.ui.adapter.base.BaseLoadingAdapter;
import com.hangzhou.xyj.ui.listener.DramaItemClickListener;
import com.hangzhou.xyj.ui.widget.CircleImageView;
import com.hangzhou.xyj.ui.widget.views.MyImageView;
import com.hangzhou.xyj.ui.widget.views.MyTextView;

import java.util.List;

/**
 * Created by yaohuix on 2016/1/27  14:21
 * <p/>
 * 说明：点唱 适配器
 */
public class SingingListAdapter extends BaseLoadingAdapter<SingModel> {


    public SingingListAdapter(RecyclerView recyclerView, List<SingModel> dataList) {
        super(recyclerView, dataList);
    }

    @Override
    public void onBindNormalViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
        final MyViewHolder holder = (MyViewHolder) viewHolder;
        if (position == 0) {
            holder.vPadding.setVisibility(View.VISIBLE);
        }
        holder.setData(mDataList.get(position));
        final SingModel model = mDataList.get(position);
        if (EIntentTagType.valueOf(mIntentTag) == EIntentTagType.TAG_STAGE_EXPERT) {//名家作品 进入
            holder.itemView.setOnClickListener(new DramaItemClickListener(mContext, mDataList,
                    position, EIntentTagType.TAG_STAGE_EXPERT));//跳转到播放界面
        } else {
            holder.itemView.setOnClickListener(new View.OnClickListener() {//跳转到录制界面
                @Override
                public void onClick(View v) {
                    DianDramaModel dramaModel = new DianDramaModel();
                    dramaModel.setId(model.getId());
                    dramaModel.setName(model.getDramaName());
                    dramaModel.setNativeUrl(model.getNativeUrl()); //原唱
                    dramaModel.setAccompanyUrl(model.getAccompanyUrl());//伴奏
                    dramaModel.setLrcUrl(model.getLrcUrl()); //歌词
                    dramaModel.setAuthor(model.getDramaSinger());
                    dramaModel.setHead(model.getShowImg());
                    IntentManager.getInstance().goRecordActivity(mContext, dramaModel, true);
                }
            });
        }
    }

    @Override
    public RecyclerView.ViewHolder onCreateNormalViewHolder(ViewGroup parent, int viewType) {
        View view = mLayoutInflater.inflate(R.layout.layout_hot_singing_item, parent, false);
        return new MyViewHolder(view);
    }

    private class MyViewHolder extends RecyclerView.ViewHolder {
        CircleImageView mIvHeader;//头像
        MyTextView mTvDramaName;//名称
        MyTextView mTvPersonName;//人名
        MyImageView mIvSing;//点唱按钮
        MyTextView mTvHotNum;//热门总数
        View vPadding;//顶部的padding

        public MyViewHolder(View itemView) {
            super(itemView);
            this.mIvHeader = (CircleImageView) itemView.findViewById(R.id.civ_header);
            this.mIvSing = (MyImageView) itemView.findViewById(R.id.miv_image);
            this.mTvDramaName = (MyTextView) itemView.findViewById(R.id.mtv_content);
            this.mTvPersonName = (MyTextView) itemView.findViewById(R.id.mtv_name);
            this.vPadding = itemView.findViewById(R.id.v_padding);
            this.mTvHotNum = (MyTextView) itemView.findViewById(R.id.mtv_hot_num);

        }

        public void setData(SingModel data) {
            mIvHeader.displayImage(data.getShowImg());
            mTvDramaName.setText(data.getDramaName());
            mTvPersonName.setText(data.getDramaSinger());
            //热门点戏进入的时候，显示热度
            if (mIntentTag == EIntentTagType.TAG_DIAN_DRAMA_HOT_SING.getValue()) {
                mTvHotNum.setVisibility(View.VISIBLE);
                mTvHotNum.setText(String.valueOf(data.getTotal()));
            }
            //戏台-名家进入的时候，显示为试听的按钮
            if (mIntentTag == EIntentTagType.TAG_STAGE_EXPERT.getValue()) {
                mIvSing.setImageResource(R.drawable.ic_already_dian);
            }
        }
    }
}
